package frame;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import dataaccess.DepotDao;
import dataaccess.RegistrationDao;
import dataaccess.StudentDao;
import entity.Depot;
import entity.Registration;
import entity.Student;
import util.Connect;

public class Control {
	
	public Control() {
		Connection con = Connect.getConnection();
	}

	public String[] getdepotname() {
		DepotDao dd = new DepotDao();
		List<Depot> deps = dd.getAll();
		String[] depotnames = new String[deps.size()];
		for (int i = 0; i < deps.size(); i++) {
			depotnames[i] = deps.get(i).getDEPOT_NAME();
		}
		return depotnames;
	}
	public Integer[] getdepotid(){
		DepotDao dd=new DepotDao();
		List<Depot> deps=dd.getAll();
		Integer[] depotid= new Integer[deps.size()];
		for (int i = 0; i < deps.size(); i++) {
			depotid[i] = deps.get(i).getDEPOT_ID();
		}
		return depotid;
		
	}
	public List<Student> getstulist(Integer index) {
		DepotDao dc = new DepotDao();
		Depot department=dc.getAll().get(index);
		List<Student> sss = department.getStuset();
		return sss;
	}

	public void insertStudent(Integer sid,String name, String address, String depotname, Integer depotid){
		StudentDao sd1=new StudentDao();
		Student sample=new Student();
		sample.setSID(sid);
		sample.setSTUDENT_NAME(name);
		sample.setSTUDENT_ADDRESS(address);
		Depot dp=new Depot();
		dp.setDEPOT_ID(depotid);
		dp.setDEPOT_NAME(depotname);
		sample.setDepot(dp);
		sample.setDEPOT_ID(depotid);
		sd1.insert(sample);
	}
	
	public void deleteStudent(Integer sid){
		StudentDao sd2=new StudentDao();
		Student sample2=new Student();
		sample2.setSID(sid);
		sd2.delete(sample2);
	}
	
	public static void main(String[] args) {
		new Control();

		// StudentDao sd=new StudentDao();
		// Student s=new Student();
		// s.setSID(1);
		// sd.delete(s);

		/*
		 * List<Student> stus=sd.getAll(); for (Student s1 : stus) {
		 * System.out.println(s1.getSID()+"  "+s1.getSTUDENT_NAME()+" "+
		 * s1.getSTUDENT_ADDRESS()+"  "+s1.getDepot().getDEPOT_NAME()); }
		 */

		/*
		 * RegistrationDao rd=new RegistrationDao(); List<Registration>
		 * reg=rd.getAll(); for (Registration r : reg) {
		 * System.out.println(r.getStudent().getSTUDENT_NAME()+" "
		 * +r.getCourse().getCOURSE_NAME()+"  "+r.getGrades()); }
		 */

		// DepotDao dd=new DepotDao();
		// List<Depot> deps=dd.getAll();
		// for (Depot d : deps) {
		// System.out.println(d.getDEPOT_NAME()+":");
		// for (Student stu : d.getStuset()) {
		// System.out.println(stu.getSTUDENT_NAME()+"
		// "+stu.getSTUDENT_ADDRESS());
		// }
		// }
	}

}
